/**
 * doctor管理初始化
 */
var Doctor = {
    id: "DoctorTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Doctor.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '医生姓名', field: 'doctorName', align: 'center', valign: 'middle', sortable: true},
        {title: '电话', field: 'doctorPhone', align: 'center', valign: 'middle', sortable: true},
        {
            title: '性别', field: 'doctorSex', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                } else {
                    return "未知"
                }
            }
        },
        {title: '生日', field: 'doctorBirthday', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true}];
};

Doctor.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Doctor.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Doctor.openAddDoctor = function () {
    var index = layer.open({
        type: 2,
        title: '添加医生',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctor/doctor_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看部门详情
 */
Doctor.openDoctorDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '医生详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doctor/doctor_update/' + Doctor.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除部门
 */
Doctor.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/doctor/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            Doctor.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Doctor.formParams = function () {
    var queryData = {};
    queryData['doctorName'] = $("#doctorName").val();
    queryData['doctorPhone'] = $("#doctorPhone").val();
    return queryData;
}

Doctor.resetSearch = function () {
    $("#doctorName").val("");
    $("#doctorPhone").val("");
    Doctor.search();
};

/**
 * 查询列表
 */
Doctor.search = function () {
    Doctor.table.refresh({query: Doctor.formParams()});
};

$(function () {
    var defaultColunms = Doctor.initColumn();
    var table = new BSTable(Doctor.id, "/doctor/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Doctor.formParams());
    Doctor.table = table.init();
    Doctor.table = table;
});
